package com.service.atf.reply.service;

import com.service.atf.base.model.Account;
import com.service.atf.base.model.TFLogin;
import com.service.atf.base.utils.ATFLogger;
import com.service.atf.reply.ac.AccountManager;
import com.service.atf.reply.core.IReadExecutor;
import com.luotao.devp.base.utils.StringUtils;

import java.util.Map;

/**
 * User: luotao
 * Date: 12-3-21
 * Time: 14:59:00
 */
public class LoginService5 implements IReadExecutor<TFLogin> {

    @Override
    public boolean isNotify() {
        return true;
    }

    @Override
    public void initOut(Map out) {
        out.put("account.getBalcCharge()", 0);
        out.put("account.getBalcAward()", 0);
        out.put("account.getFrezCharge()", 0);
        out.put("account.getFrezAward()", 0);
        out.put("account.getTmpAward()", 0);
        out.put("account.getRemainCountCharge()", 0);
        out.put("account.getRemainCountCash()", 0);
        out.put("account.getRemainCountSale()", 0);
        out.put("account.getRemainCharge()", 0);
        out.put("account.getRemainCash()", 0);
        out.put("account.getRemainSale()", 0);
        out.put("account.getRemainGameTime()", 0);
        out.put("account.getLastFlowId()", 0);
    }

    @Override
    public void execute(boolean recover, AccountManager accountManager, TFLogin login, Map out) {
        ATFLogger.sysinfo("enter login");
//    Validata.validataCustomerCode(this, login.getCustomerCode());
//    Validata.validataCustomerCodeLength(this, login.getCustomerCode());
        Account account = accountManager.getBussAccount(login.getCustomerCode());
        ATFLogger.sysdebug("account = " + account);
        if (account != null && !StringUtils.isEmpty(account.getCustomerCode())) {
            byte[] accData = account.object2Byte();
            //У��AC������Ϣ
            //   Validata.validataAccountLen(this, accData.length);
            //todo test_code
//      account.setLastFlowId("");
//      account.setRemainGameTime(login.getEveryDayGameTime()-login.getDailyGameTime());
            account.setToken(login.getToken());
            //�û���Ϣ�ŵ�ac��
            accountManager.updateAccount(account);
            //���سɹ���Ϣ
        } else {
            account = accountManager.getEmptyAccount();
            //����һ���յ��˻�����
            account.setCustomerCode(login.getCustomerCode());
            account.setToken(login.getToken());
            account.setBalcCharge(login.getBalcCharge());
            account.setBalcAward(login.getBalcAward());
            account.setRemainCountCharge((short) (login.getEveryDayChargeCount() - login.getDailyChargeCount()));
            account.setRemainCountCash((short) (login.getEveryDayCashCount() - login.getDailyCashCount()));
            account.setRemainCountSale((short) (login.getEveryDaySaleCount() - login.getDailySaleCount()));


            account.setRemainCharge(login.getEveryDayChargeAmount() - login.getDailyChargeAmount());
            account.setRemainCash(login.getEveryDayCashAmount() - login.getDailyCashAmount());
            account.setRemainSale(login.getEveryDaySaleAmount() - login.getDailySaleAmount());
            account.setRemainGameTime(login.getEveryDayGameTime() - login.getDailyGameTime());

            account.setMaxCharge(login.getEveryChargeAmount());
            account.setMinDraw(login.getEveryCashMin());
            account.setMaxDraw(login.getEveryCashMax());
            account.setMaxConsume(login.getEverySaleAmount());

            account.setLastFlowId(login.getLastFlowId());
            account.setStartTime(0);
            account.setMd5Bingo(login.getLastFlowId(), login.getAwardMoney());


            account.setEveryDayChargeCount(login.getEveryDayChargeCount());
            account.setEveryDayCashCount(login.getEveryDayCashCount());
            account.setEveryDaySaleCount(login.getEveryDaySaleCount());

            account.setEveryDayChargeAmount(login.getEveryDayChargeAmount());
            account.setEveryDayCashAmount(login.getEveryDayCashAmount());
            account.setEveryDaySaleAmount(login.getEveryDaySaleAmount());
            account.setEveryDayGameTime(login.getEveryDayGameTime());
            account.setConcurrLock((byte) 0);
            byte[] accData = account.object2Byte();
            //У��AC������Ϣ
            //    Validata.validataAccountLen(this, accData.length);
            //�û���Ϣ�ŵ�ac��
            accountManager.addToAccountByte(account);
            //���سɹ���Ϣ
        }
        out.put("account.getBalcCharge()", account.getBalcCharge());
        out.put("account.getBalcAward()", account.getBalcAward());
        out.put("account.getFrezCharge()", account.getFrezCharge());
        out.put("account.getFrezAward()", account.getFrezAward());
        out.put("account.getTmpAward()", account.getTmpAward());

        out.put("account.getRemainCountCharge()", account.getRemainCountCharge());
        out.put("account.getRemainCountCash()", account.getRemainCountCash());
        out.put("account.getRemainCountSale()", account.getRemainCountSale());

        out.put("account.getRemainCharge()", account.getRemainCharge());
        out.put("account.getRemainCash()", account.getRemainCash());
        out.put("account.getRemainSale()", account.getRemainSale());

        out.put("account.getRemainGameTime()", account.getRemainGameTime());
        out.put("account.getLastFlowId()", account.getLastFlowId());
    }
}
